package com.xunkids.bos.migration.component.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * logger util
 *
 * @author baiyanlong
 * @version 1.0.0
 * @since 2022/12/11 14:24
 */
public class LoggerHelp {

    private static final Map<String, Logger> LOGGER_MAP = new ConcurrentHashMap<>(8);


    public static Logger getLogger(String name) {
        Logger logger = LOGGER_MAP.putIfAbsent(name, LoggerFactory.getLogger(name));
        if (logger == null) {
            logger = LOGGER_MAP.putIfAbsent(name, LoggerFactory.getLogger(name));
        }
        return logger;
    }


    public static Logger getLogger(Class<?> clazz) {
        String name = clazz.getName();
        Logger logger = LOGGER_MAP.putIfAbsent(name, LoggerFactory.getLogger(name));
        if (logger == null) {
            logger = LoggerFactory.getLogger(name);
            LOGGER_MAP.put(name, logger);
        }
        return logger;
    }

    public static Logger remove(String name) {
        return LOGGER_MAP.remove(name);
    }

    public static void clear() {
        LOGGER_MAP.clear();
    }

}
